// #packager-optimize

(function() {

    var $u = juliet.using({ uidGenerator : 'juliet.core.uidGenerator-0.1' });

    var $ = juliet.jQuery;

    var funcModule = {

        proxiesCache : { },

        proxy : function(fn, context) {
            if ( fn.proxyUid ) return this.proxiesCache[fn.proxyUid];

            var fnProxy = function() {
                return fn.apply(context, arguments);
            };

            fn.proxyUid = $u('uidGenerator').getUid();
            this.proxiesCache[fn.proxyUid] = fnProxy;

            return fnProxy;
        },

        /*
         * @Deprecated
         */
        bindEventHandler : function() {
            this.bind.apply(this, arguments);
        },

        bind : function(selector, event, handler, ctx) {
            $(selector).bind(event, this.proxy(handler, ctx));
        },

        unbind : function(selector, event, handler, ctx) {
            $(selector).unbind(event, this.proxy(handler, ctx));
        },

        delay : function(fn, context, time) {
            var timeout = setTimeout(this.proxy(fn, context), time);
            return { abort : function() { clearTimeout(timeout); } };
        }

    };

    juliet.registerModule('juliet.core', 'func-0.1', funcModule);

})();
